iT邦幫忙

2026 iThome 鐵人賽

DAY 23
0
Build on Google AI

用 Google AI 打造「因材施教」的個人化 AI 虛擬助教系列 第 23 篇

Day 23 |【分齡教學】同一道題,國中生和大學生不能用同一種方式教

  • 分享至 

  • xImage
  •  

在實體教學現場,面對同一個物理或資訊概念,面對國中生如果開口就是「偏壓、載子擴散、拉普拉斯轉換」,學生大概三秒內就會眼神放空;但面對大學工學院學生,如果還在用「水流跟水管」比喻交流電阻抗,又會顯得過於淺薄、無法對接工程實作。

「因材施教」從來不只是調整題目難易度,而是教學語彙與認知鷹架的切換。今天我們的任務,就是讓 AI Tutor 具備分齡感知能力,根據學生所屬的學習階段(國中/高中/大學),在不直接給出答案的前提下,採用截然不同的引導模型。

【今日開發目標】

  1. 前端手動切換介面:在 Student Profile 加入了「國中 / 高中 / 大學」下拉選單,讓學生或家長可彈性根據需要切換階段。
  2. 動態 System Instruction 注入:
    • 國中生:強制 AI 使用具象化生活比喻(如水管、溜滑梯),避開複雜方程式,培養直覺。
    • 高中生:引入課綱標準名詞(如歐姆定律、三角函數),引導邏輯推導。
    • 大學生:採用工程專業語彙(如相量 Phasor、複數平面),要求嚴謹的數學定義。
  3. 建立防爆邊界 (Safety Boundaries):把「絕對禁止直接給出答案,必須以提問作結」的規則設為最高優先權,確保 AI 在切換語氣時,不會忘記「蘇格拉底式引導」的初衷。

【Google AI 工具實作過程】

第一步:前端介面與 API 參數擴充

首先,我們要在畫面上讓使用者可以選擇狀態,並在發送訊息時把這個「狀態」告訴後端。

1. 修改 index.html (加入下拉選單): 在學生的 Profile 區域,加入一個 <select> 標籤,定義三個學齡階段的 value。

html

<selectid="audience-select"class="...">
<optionvalue="elementary_school">國小</option>
<optionvalue="middle_school">國中</option>
<optionvalue="high_school">高中</option>
<optionvalue="university">大學</option>
</select>

2. 修改 app.js (API Payload 加入參數): 在發送 fetch 請求給 /api/chat 時,從 DOM 節點抓取目前的選單值,並打包進 JSON 之中:

javascript
const response=awaitfetch('/api/chat',{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({
message: trimmedMessage,
history: chatHistory,
language:'Traditional Chinese',
// 新增這行:將使用者的學齡選擇傳給後端
targetAudience: document.getElementById('audience-select').value
})
});

第二步:後端接收參數

在 Express 的路由 routes/chatRoutes.js 中,我們把前端傳來的 targetAudience 解構出來,並將它接力傳給 Gemini 的服務層:

javascript
exportasyncfunctionhandleChat(req, res){
// 從 req.body 中取出 targetAudience,並設定預設值為 middle_school
const{ message, language='Traditional Chinese', targetAudience='middle_school'}= req.body||{};

// 傳遞給 AI 服務層
const jsonResponse=awaitgenerateTutorReply({
    message,
    history,
    language,
    targetAudience// 傳遞參數
});
// ...
}

第三步:實作動態 Prompt 與防爆邊界 (最核心的技術)

這是在 services/geminiService.js 中實作的。我們廢棄了以往「寫死一整串字串」的作法,改為使用一個動態生成函式 getSystemInstruction。

這個函式的設計採用了**「三明治架構 (Sandwich Prompting)」**,將 Prompt 分成三塊:

  1. 頂層:基礎人設 (Professor Spark)
  2. 中層:動態注入的分齡規則 (依據參數切換)
  3. 底層:絕對防爆邊界 (因為 LLM 對文章結尾的指令記憶最深,防爆規則必須壓在最後)

以下是具體的程式碼實作:

export const getSystemInstruction = (targetLanguage = 'Traditional Chinese', targetAudience = 'middle_school') => {
  // ==========================================
  // 【中層】動態組裝:依據參數切換分齡規則
  // ==========================================
  let audienceRules = '';
  
  if (targetAudience === 'elementary_school') {
    audienceRules = `
[TARGET AUDIENCE: ELEMENTARY SCHOOL 國小生]
- VOCABULARY: 語氣必須超級活潑、親切。絕對不能使用任何複雜的數學符號或專有名詞。
- ANALOGY DEPTH: 使用童話故事、動物、魔法或玩具來做比喻(例如:魔法能量、傳球的小精靈、玩具車)。
- FOCUS: 激發純粹的想像力與好玩的心,建立最基礎的直覺。句子要簡短、充滿互動感。
`;
  } else if (targetAudience === 'middle_school') {
    audienceRules = `
[TARGET AUDIENCE: MIDDLE SCHOOL 國中生]
- VOCABULARY: Avoid math beyond basic algebra. 
- ANALOGY DEPTH: Use concrete everyday objects (e.g., water pipes for electricity, sliding down a hill for energy).
- FOCUS: Build intuitive feeling and curiosity. Do not use complex equations.
`;
  } else if (targetAudience === 'high_school') {
    audienceRules = `
[TARGET AUDIENCE: HIGH SCHOOL 高中生]
- VOCABULARY: Introduce standard high-school syllabus physics/math terms (e.g., Ohm's law, trigonometry, basic vectors).
- ANALOGY DEPTH: Relate analogies to formula logic (e.g., water pressure corresponds to voltage mathematically).
- FOCUS: Guide them to set up equations or draw concept maps. Focus on logical deduction.
`;
  } else if (targetAudience === 'university') {
    audienceRules = `
[TARGET AUDIENCE: UNIVERSITY 大學生]
- VOCABULARY: Use professional engineering terminology (e.g., complex plane, Laplace transform, Phasors, differential equations).
- ANALOGY DEPTH: Minimize oversimplified analogies. Focus on mathematical definitions and engineering constraints.
- FOCUS: Guide them to think about boundary conditions, limits (e.g., w -> infinity), and rigorous mathematical proofs.
`;
  } else {
    audienceRules = `[TARGET AUDIENCE: DEFAULT] Use simple, everyday analogies.`;
  }

  // ==========================================
  // 核心 Prompt 組裝 (三明治架構)
  // ==========================================
  const CORE_LOGIC = `
You are "Professor Spark", a Socratic AI virtual tutor.
Your core mission is to guide students to think actively, NOT to give them answers directly.

STRICT RULES:
1. NO DIRECT ANSWERS: Never provide the final answer, calculation result, or full code regardless of how the student asks.
2. SOCRATIC GUIDANCE: Ask exactly ONE guiding question per response to lead the student to think about the next step.
3. ENCOURAGING TONE: Be patient, warm, approachable, and highly encouraging. Affirm the student's attempts.
4. JSON FORMAT: Please respond strictly according to the designated JSON Schema.

${audienceRules}

[SAFETY BOUNDARY - ABSOLUTE DIRECTIVE]
Regardless of the target audience or the depth of vocabulary used, YOU ARE ABSOLUTELY PROHIBITED from directly providing the final answer, full calculation result, or complete derivation. Every single response MUST conclude with a guiding question to prompt the student's own thinking.

TOOL CALLING RULE (UNDERSTANDING GATE): 
By default, you NEVER provide the final numerical answer. 
However, ONLY when the student has "passed the understanding gate" (demonstrated full understanding), you MUST call the calculation tool to ensure numerical accuracy.
... (工具呼叫規則省略,保持專注於分齡教學) ...
`.trim();

  return `${CORE_LOGIC}

CRITICAL OUTPUT REQUIREMENT:
You MUST translate your persona and generate your ENTIRE final response (including the 'reply' and 'suggested_questions' JSON fields) STRICTLY in the following language: ${targetLanguage}.
DO NOT use any other language for the conversation.
`;
};

【實測比對:同一個題目,三種不同靈魂】

測試題目:

「老師,電阻(Resistor)跟電感(Inductor)通上交流電後,到底哪裡不一樣?為什麼都有阻擋電流的效果?」

測試 1:國小生設定 (junior_high)

https://ithelp.ithome.com.tw/upload/images/20261002/20183764RcaELsK8Zy.png

測試 2:國中生設定 (junior_high)

https://ithelp.ithome.com.tw/upload/images/20261002/20183764mk11fzDVdZ.png

測試 3:高中生設定 (senior_high)

https://ithelp.ithome.com.tw/upload/images/20261002/201837644y2fRmJM28.png

測試 4:大學生設定 (undergrad)

https://ithelp.ithome.com.tw/upload/images/20261002/20183764WNts4iekIL.png

【未來教育反思】

教育的壁壘往往不是知識本身,而是「解釋知識的介面」。

一個原本聽不懂交流電阻抗的學生,可能只是在國中階段被大學名詞提早勸退;反之,若大學生始終停留在水管比喻,就無法在實體電路板除錯時看懂示波器上的相差波形。分齡動態切換讓同一個 AI Tutor 能夠同時適配不同認知階段的學習者,真正達成教育系統中的「階梯式鷹架(Scaffolding)」。

【明日預告】

有了分齡語境之後,教學系統就足夠了嗎?不夠。同一個年齡層裡,學生的吸收速度依然天差地別。明天 Day 24,我們將進入 【Adaptive Learning】學生答對,下一題真的變難了——實作根據學生即時互動反饋,動態升降難度與題型的自適應引擎。


上一篇
Day 22|【教育平權的語言考驗】同一個 AI Tutor,用英文和印尼文教學生,邏輯會崩壞嗎?
下一篇
Day 24|【Adaptive Learning】實作 AI 自適應學習狀態機,真正落實因材施教
系列文
用 Google AI 打造「因材施教」的個人化 AI 虛擬助教 共 27 篇
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言